package com.example.backend.controller;
import com.example.backend.common.Result;
import com.example.backend.services.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BookController {
    @Autowired
    BookService bookService;
    @GetMapping("/getBookList")
    public Result getBookList() {
        System.out.println("getBookList");
        Result result=bookService.getBookList();
        System.out.println(result.getMsg());
        return result;
    }
    @GetMapping("/returnBook")
    public Result returnBook(@RequestParam String borrow_id) {
        System.out.println("returnBook"+borrow_id);
        return bookService.returnBook(borrow_id);
    }
    @GetMapping("/borrowBook")
    public Result borrowBook(@RequestParam String uid,@RequestParam String bid) {
        System.out.println("borrowBook"+bid);
        return bookService.borrowBook(uid,bid);
    }
    @GetMapping("/searchByBook")
    public Result searchByBook(@RequestParam String name) {
        System.out.println("searchByBook"+name);
        return bookService.searchByBook(name);
    }
    @GetMapping("/submitNewBook")
    public Result submitNewBook(@RequestParam String name,@RequestParam String author, @RequestParam int total_copies) {
        System.out.println("submitNewBook"+name+String.valueOf(total_copies));
        return bookService.submitNewBook(name,author,total_copies);
    }
}
